<template>
	<view class="order">
		<mescroll-body @init="mescrollInit" :sticky="true" :down="down" @down="downCallback" @up="upCallback">
			<view class="sticky-tabs">
				<view class="nav">
					<view class="back" @click="goBack">
						<uni-icons type="back" :size="22" color="#333333" v-if="isShowBack"></uni-icons>
					</view>
					<view class="search-content">
						<image src="../../static/index/search.png" mode=""></image>
						<input type="请输入" v-model="search" placeholder="请输入技师或用户姓名电话" placeholder-class="input-placeholder" />
						<view class="search-btn" @click="handleToSearch">搜索</view>
					</view>
				</view>
				<view class="tabbar">
					<view @click="onTab(0)" :id="tab==0?'select':''">全部<i v-if="tab == 0"></i></view>
					<view @click="onTab(1)" :id="tab==1?'select':''">待接单<i v-if="tab == 1"></i></view>
					<view @click="onTab(2)" :id="tab==2?'select':''">待服务<i v-if="tab == 2"></i></view>
					<view @click="onTab(3)" :id="tab==3?'select':''">已完成<i v-if="tab == 3"></i></view>
				</view>
			</view>
			<view class="list">
				<view class="item" v-for="(item,index) in list" :key="index" >
					<view class="name">
						<view class="logo">
							<view class="inner-img">
								<image src="https://qiniu-cdn.maeiyun.com/imgs/shangjia/anmo.png"></image>
							</view>
							<text>{{item.title}}</text>
						</view>
						<view class="status">
							<text style="color: #EF4C28;" v-if="item.status == 2 && item.jiedan_time ==0">待接单</text>
							<text style="color: #FFAC00;" v-if="item.status==2 && item.jiedan_time>0">待服务</text>
							<text style="color: #A2A2A2;" v-if="item.status== 4 || item.status== 6">已完成</text>
						</view>
					</view>
					<view class="product">
						<image :src="item.images[0]"  mode="aspectFill"></image>
						<view class="detail">
							<view class="title">{{item.spec_name}}</view>
							<view class="text">{{item.subscribe_time}}</view>
							<view class="text">总价: <text style="color:#FF0000;">￥{{item.price}}</text></view>
							<view class="text">技师: <text style="color:#333333;">{{item.technician.real_name}}</text>	</view>
						</view>
					</view>
					<view class="bottom-info">
						<view class="user-name">
							<view class="info-lines">
								<text class="title">用户姓名:</text>
								{{item.address.real_name}}
							</view>
							<view class="info-lines" @click="callphone(item.address.mobile)">
								<text class="title">联系方式:</text>
								{{item.address.mobile}}
								<image src="https://qiniu-cdn.maeiyun.com/imgs/shangjia/phone.png" mode=""></image>
							</view>
						</view>
						<view>
							<text class="title">用户地址:</text>	{{item.address.address}}
						</view>
						
						
					</view>
					
					
					<view v-if="item.status == 2 && item.jiedan_time ==0" class="btn flex_r_between">
						<text @click="onGetOrder(item)">接单</text>
					</view>
					
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				search: '',
				tab: 0,
				list: [],
				isShowBack: false,
				menuList: [{
					'title': '订单类型',
					'type': 'custom',
					'key': 'custom1',
					'isMutiple': true, //多选
					'detailList': [{
						title: '上门服务',
						value: "1",
						isSelected: true
					}, {
						title: '酒店',
						value: "2",
					}, {
						title: '门票',
						value: "3",
					}, {
						title: '电影票',
						value: "4",

					}],
				}],
				// 类型:1=上门服务,2=酒店,3=门票,4=电影票,5=开通会员
				screen: [1, 2, 3, 4], // 筛选结果
				down: {
					auto: false
				},
				page: 1,
				show:false,
				currentOrder:{}
			}
		},
		components: {
		},
		onShow() {
			// this.mescroll && this.mescroll.triggerDownScroll()

		},
		methods: {
			onGetOrder(e){
				this.request.httpTokenRequest({
					url: "store.order/jiedan",
					method: "get"
				}, {
					order_id:e.id
				}).then(res=> {
					this.$util.msg(res.msg)
					if (res.code == 0) {
						this.list = []
						this.mescroll.resetUpScroll();
					}
				})
			},
			callphone(phone) {
				this.$util.makeCall(phone)
			},
			handleToSearch() {
				this.downCallback()
			},
			onTab(e) {
				this.tab = e
				this.page = 1
				this.downCallback()
			},
			imageError(e,item){
				if(item.type == 1){
					item.service.images[0] = 'https://qiniu-cdn.maeiyun.com/imgs/hotel/error-2.png'
				}else if(item.type == 2){
					item.hotel_image = 'https://qiniu-cdn.maeiyun.com/imgs/hotel/error-2.png'
				}else if(item.type == 3){
					item.images[0] = 'https://qiniu-cdn.maeiyun.com/imgs/hotel/error-2.png'
				}else if(item.type == 4){
					item.pic = 'https://qiniu-cdn.maeiyun.com/imgs/hotel/error-2.png'
				}
			},
			goBack() {
				uni.navigateBack()
			},
			downCallback(page) {
				this.list = []
				this.mescroll.resetUpScroll();
			},
			upCallback(page) {
				var that = this
				this.request.httpTokenRequest({
					url: "store.order/getOrderList",
					method: "get"
				}, {
					status: this.tab,
					key: this.search,
					page:page.num
				}).then(function(res) {
					if (res.code == 0) {
						that.list = [...that.list, ...res.data.data]
						that.page++
						that.mescroll.endSuccess(that.list.length)
					} else {
						that.mescroll.endErr()
					}
				})
			}

		},
		onLoad(option) {
			if (option.type || option.type === 0) {
				this.tab = option.type
				this.isShowBack = true
			} else {
				this.isShowBack = false
			}
		}
	}
</script>

<style scoped lang="scss">
	.order {
		min-height: 100vh;
		background: #F5F7F8;
		box-sizing: border-box;
	}

	.sticky-tabs {
		z-index: 990;
		position: sticky;
		top: 0;
		background: #F5F7F8;
		// z-index: 1000;
	}

	.nav {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: calc(var(--status-bar-height) + 10px)  30rpx 0 30rpx ;
		// height: 70px;
		width: 100vw;
		background: #F5F7F8;
		z-index: 99;
		box-sizing: border-box;

		.search-content {
			width: 625rpx;
			display: flex;
			align-items: center;
			border-radius: 32rpx;
			border: 1rpx solid #2E7EFA;
			backdrop-filter: blur(10px);
			padding: 7rpx 10rpx 7rpx 23rpx;

			image {
				width: 30rpx;
				height: 30rpx;
				flex: 0 0 auto;
				margin-right: 20rpx;
			}

			input {
				width: 68%;
			}

			.input-placeholder {
				font-size: 28rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #AEAEB0;
			}

			.search-btn {
				width: 103rpx !important;
				height: 50rpx;
				background: #2E7EFA;
				border-radius: 32rpx;
				backdrop-filter: blur(10px);
				font-size: 26rpx;
				line-height: 50rpx;
				text-align: center;
				color: #fff;
				font-family: PingFangSC, PingFang SC;
				margin-left: auto;
			}
		}

		.icon {
			display: flex;
			align-items: center;

			view {
				display: flex;
				align-items: center;
				flex-direction: column;
				margin-left: 30rpx;

				image {
					width: 22rpx;
					height: 24rpx;
				}

				text {
					font-size: 26rpx;
					color: #333333;
					line-height: 37rpx;
				}
			}
		}
	}

	.tabbar {
		padding: 20rpx 32rpx 25rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
		// overflow: hidden;
		background-color: #F5F7F8;

		view {
			height: 39rpx;
			font-size: 30rpx;
			color: #08090A;
			line-height: 39rpx;
			position: relative;

			i {
				position: absolute;
				bottom: 0;
				left: 10%;
				width: 80%;
				height: 11rpx;
				background:  rgba(46,126,250,0.6);
				border-radius: 4rpx 4rpx 4rpx 4rpx;
			}
		}
	}

	.list {
		padding: 0 30rpx;
		.item {
			background: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin-bottom: 30rpx;
			.btn {
				margin-top: 30rpx;
				flex-direction: row-reverse;
				text {
					background: #3393FF;
					border-radius: 34rpx;
					padding: 14rpx 40rpx;
					font-size: 30rpx;
					color: #FFFFFF;
				}
			}

			.name {
				display: flex;
				align-items: flex-start;
				justify-content: space-between;

				.logo {
					display: flex;
					align-items: center;
					.inner-img {
						width: 40rpx;
						height: 40rpx;
						margin-right: 10rpx;
					}

					image {
						width: 40rpx;
						height: 40rpx;
					}

					text {
						font-size: 30rpx;
						font-weight: 400;
						color: #08090A;
						line-height: 42rpx;
						flex-grow: 1;
						width: 80%;
					}
				}

				.status {
					font-size: 26rpx;
					line-height: 37rpx;
					white-space: nowrap;
				}
			}

			.product {
				display: flex;
				margin: 30rpx 0 30rpx;

				image {
					width: 142rpx;
					height: 190rpx;
					margin-right: 23rpx;
				}

				.detail {
					flex: 1;

					.title {
						font-size: 28rpx;
						font-weight: 600;
						color: #333333;
						line-height: 40rpx;
					}

					.text {
						font-size: 24rpx;
						color: #656667;
						line-height: 33rpx;
						margin-top: 10rpx;
					}
				}
			}
			.bottom-info{
				background: #F5F7F8;
				border-radius: 10rpx;
				opacity: 0.8;
				padding: 20rpx;
				font-size: 24rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				line-height: 33rpx;
				color: #333333;
				.user-name{
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 10rpx;
					.info-lines{
						image{
							width:22rpx;
							height: 22rpx;
							margin-left: 36rpx;
						}
					}
				}
				text{
					color: #656667 !important;
				}
			}

		}
	}
</style>